package com.koron.order.risk.base.bean.vo;

import cn.hutool.core.collection.CollUtil;
import com.koron.order.risk.base.bean.po.LineRisk;
import com.koron.order.risk.base.bean.po.LineRiskPart;
import com.koron.order.risk.util.LineRiskConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
 * @author jzp
 * @since 2022/12/15
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ApiModel(value="风险管控单列表页", description = "LineRiskVO")
public class LineRiskVO extends LineRisk {

    @ApiModelProperty(value = "当前节点名称")
    private String currNodeName;

    @ApiModelProperty(value = "当前节点处理人账号")
    private String currNodeAccount;

    @ApiModelProperty(value = "当前节点处理人")
    private String currNodeUser;

    @ApiModelProperty(value = "当前节点编码")
    private String currNodeCode;

    @ApiModelProperty(value = "塔段信息")
    private List<LineRiskPart> lineRiskPartList;

    public String getLineRiskPartStr() {
        if (CollUtil.isEmpty(lineRiskPartList)) {
            return null;
        }
        if (lineRiskPartList.size() == 1) {
            return lineRiskPartList.get(0).getEquipmentName();
        } else {
            String first = lineRiskPartList.get(0).getEquipmentName();
            String last = lineRiskPartList.get(lineRiskPartList.size() - 1).getEquipmentName();
            return first + "~" + last;
        }
    }

    /**
     * 落实状态：只有风险管控单状态为“风险管控中” 才显示落实状态，此状态为管控管控措施中的落实状态
     */
    @Override
    public String getWorkableStatus() {
        if (LineRiskConstant.Status.MANAGEMENT.equals(getStatus())) {
            return super.getWorkableStatus();
        }
        return null;
    }

    public LineRiskExcel toExcel() {
        LineRiskExcel lineRiskExcel = new LineRiskExcel();
        lineRiskExcel.setTitle(getTitle());
        lineRiskExcel.setEquipmentName(getEquipmentName());
        lineRiskExcel.setLineRiskPartStr(getLineRiskPartStr());
        lineRiskExcel.setFollowDeptName(getFollowDeptName());
        lineRiskExcel.setRiskType(getRiskType());
        lineRiskExcel.setRiskKeyword(getRiskKeyword());
        lineRiskExcel.setRiskLevel(getRiskLevel());
        lineRiskExcel.setInfluenceForLine(getInfluenceForLine());
        lineRiskExcel.setHandlerWay(getHandlerWay());
        lineRiskExcel.setRiskSource(getRiskSource());
        lineRiskExcel.setFinderName(getFinderName());
        lineRiskExcel.setFindTime(getFindTime());
        lineRiskExcel.setDescr(getDescr());
        lineRiskExcel.setSuggestion(getSuggestion());
        lineRiskExcel.setRemark(getRemark());
        return lineRiskExcel;
    }
}
